<template>
  <div class="chart-container" ref="chartRef"></div>
</template>

<script lang="ts">
export default {
  name: "ProgressChart",
};
</script>

<script lang="ts" setup>
import * as echarts from "echarts";
import { ref, watch } from "vue";

const chartRef = ref();
const props = defineProps<{
  usersLastMonth: number;
}>();

watch(
  () => props.usersLastMonth,
  () => {
    const myEchart = echarts.init(chartRef.value);
    const option = {
      xAxis: {
        min: 0,
        max: 100,
        show: false,
      },

      grid: {
        left: 0,
        right: 0,
      },
      yAxis: {
        data: ["百分比"],
        show: false,
      },
      series: {
        type: "bar",
        data: [props.usersLastMonth],
        barWidth: 10,
        showBackground: true,
        itemStyle: {
          color: "yellowgreen",
        },
        label: {
          show: true,
          position: "right",
          formatter: "|",
          color: "yellowgreen",
        },
      },
      tooltip: {},
    };
    myEchart.setOption(option);
  }
);
</script>

<style scoped>
.chart-container {
  height: 100%;
}
</style>
